class ServicesController < ApplicationController
  layout "popup"
  protect_from_forgery :only => [:create, :destroy, :update]

  def index
    @services = Service.find(:all)

    respond_to do |format|
      format.html
      format.xml  { render :xml => @services }
    end
  end

  def new
    @service = Service.new

    respond_to do |format|
      format.html
      format.xml  { render :xml => @service }
    end
  end

  def edit
    @service = Service.find(params[:id])
  end

  def create
    @service = Service.new(params[:service])

    respond_to do |format|
      if @service.save
        flash[:notice] = 'Servizio creato con successo.'
        format.html { redirect_to(services_url) }
        format.xml  { render :xml => @service, :status => :created, :location => @service }
        format.js { render :action => "create.rjs" }
      else
        flash[:notice] = 'Servizio non creato!'
        format.html { render :action => "new" }
        format.xml  { render :xml => @service.errors, :status => :unprocessable_entity }
        format.js { render :action => "shared/error.rjs" }
      end
    end
  end

  def update
    @service = Service.find(params[:id])

    respond_to do |format|
      if @service.update_attributes(params[:service])
        flash[:notice] = 'Servizio aggiornato con successo.'
        format.html { redirect_to(services_url) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @service.errors, :status => :unprocessable_entity }
      end
    end
  end

  def destroy
    @service = Service.find(params[:id])
    @service.destroy

    respond_to do |format|
      format.html { redirect_to(services_url) }
      format.xml  { head :ok }
    end
  end
end
